//
//  MeLiveFilterView.m
//  MeLive
//
//  Created by liulei on 2017/5/10.
//  Copyright © 2017年 liulei. All rights reserved.
//

#import "MeLiveFilterView.h"
#import "MeLiveCagtIcon.h"

@interface MeLiveFilterView ()
@property (nonatomic, weak) UIScrollView *scrollView;
@property (nonatomic, strong) NSArray *titleArr;
@property (nonatomic, strong) NSArray *iconArr;
@end

@implementation MeLiveFilterView

- (NSArray *)titleArr{
    if (_titleArr == nil) {
        _titleArr = [NSMutableArray arrayWithObjects:@"无滤镜", @"浪漫", @"清新", @"唯美", @"粉嫩", @"怀旧", @"蓝调", @"清凉", @"日系", nil];
    }
    return _titleArr;
}

- (NSArray *)iconArr{
    if (_iconArr == nil) {
        _iconArr = [NSMutableArray arrayWithObjects:@"live_filter_none_c.png", @"live_filter_langman_c.png", @"live_filter_qingxin_c.png", @"live_filter_weimei_c.png", @"live_filter_fennen_c.png", @"live_filter_huaijiu_c.png", @"live_filter_landiao_c.png", @"live_filter_qingliang_c.png", @"live_filter_rixi_c.png", nil];
    }
    return _iconArr;
}

- (instancetype)initWithBeautyViewW:(CGFloat)beautyW
{
    if (self = [super init]) {
        
        self.backgroundColor = [UIColor clearColor];
        [self addContentView:beautyW];
    }
    return self;
}

- (void)addContentView:(CGFloat)beautyW{
    // 添加背景scrollView
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    [self addSubview:scrollView];
    scrollView.backgroundColor = [UIColor clearColor];
    scrollView.frame = CGRectMake(0, 0, beautyW, 70);
    scrollView.contentSize = CGSizeMake(beautyW*2, 70);
    scrollView.bounces = YES;
    scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView = scrollView;
    
    self.scrollView.contentSize = CGSizeMake(50*9, 70);
    for (int i = 0; i < 9; ++i) {
        
        MeLiveCagtIcon *rookieView = [MeLiveCagtIcon icon];
        rookieView.backgroundColor = [UIColor clearColor];
        rookieView.width = 50;
        rookieView.x = i * 50;
        [_scrollView addSubview:rookieView];
        rookieView.filterLabel.text = self.titleArr[i];
        rookieView.filterLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
        rookieView.filterLabel.hidden = NO;
        rookieView.filterImageView.image = [UIImage imageNamed:self.iconArr[i]];
        rookieView.filterImageView.hidden = NO;
        
        //  添加手势
        rookieView.tag = i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rookieViewTapped:)];
        [rookieView addGestureRecognizer:tap];
        UIView *singleTapView = [tap view];
        singleTapView.tag = i;
    };
}

- (void)rookieViewTapped:(UIGestureRecognizer *)tap
{

    if ([self.delegate respondsToSelector:@selector(didSelectFilterInXLJLiveFileterView:selectIndex:)]) {
        
        [self.delegate didSelectFilterInXLJLiveFileterView:self selectIndex:tap.view.tag];
    }
}

@end
